/**
 * Created by Brant on 2016/12/28.
 */
module.exports = function ($rootScope, $scope,$window,$state,$timeout,workBarService,httpservice,$cookies,caseBarService,newCase
  ,caseBarDetailBarService,caseBarDetailjinchengService,caseBarDetailZhengService,feedbackService,invitationService,caseBarDetailxiaService,pdfDelegate) {
    /*用户Id和pwd的默认缓存时间*/
    var expireDate = new Date();
    expireDate.setDate(expireDate.getDate() + 1);

    /*登录ID*/
    $scope.loginId = kbt.decrypt($cookies.get('cookieUserId'));

    //当前用户的名字
    $scope.taskuserName=$cookies.get('userPortraitName');
  $rootScope.typeIf=$cookies.get('type')

    //默认隐藏
    $("#menuportrait").hide();

    $scope.tempCaseName = "";
    $scope.caseSelected = "";
    $scope.stageSelected = "";
    $scope.caseLawyers = "";
    $scope.caseLawyerNames = new Array();
    $scope.caseLawyerIds = new Array();
    var tempLawyerId = "";

    $scope.pdfUrl = '';

    //用户名字
    $scope.userName = '';
    //头像地址
    $scope.headImageUrl = '';
    // 任务详情对象
    $scope.tashDetailPara = new Object();

  $rootScope.preViewHref = '';

    $scope.init = function () {
        /*$('#Bar').children('li').click(function () {
            $(this).siblings('li').removeClass('active');
            $(this).addClass('active');
            var index = $("#Bar li").index($(this));

            $cookies.put('leftBarIndex', index, {
              expires: expireDate
            });
        });*/
        //查询用户信息,获取图片
        $scope.queryUserInfo();
        /*var leftBarIndex = $cookies.get('leftBarIndex');
        if (leftBarIndex != "" && leftBarIndex != null && leftBarIndex != "undefined") {
            $('#Bar li').removeClass('active');
            $('#Bar li').eq(leftBarIndex).addClass('active');
        }*/
    };

  $scope.showTask=function(){
    $(".task-lawyer-list").addClass('hide');
  }


    // 搜索案例
    $scope.getcondition = function () {
        var name = document.getElementById("name").value;
        name = name.replace(/(^\s*)|(\s*$)/g, "");
        $scope.messages = name;
        $scope.floast = true;
        if ($scope.messages != '' && $scope.messages != null && typeof ($scope.messages) != "undefined") {
            $state.go('caseBarDetailAnLi2', {messages: $scope.messages});
        } else {

        }
    };

    // 关闭弹出时，清空界面输入值
    $('#taskModal').on('hidden.bs.modal', function () {
        $scope.tempCaseName = '';
        $scope.taskContent = '';
        $scope.caseSelected = '';
        $scope.stageSelected = '';
        $scope.stageList = '';
        $scope.taskDate = '';
        $(".task-caseText").html("请选择");
        $(".task-stageText").html("请选择");

        $scope.caseLawyerNames.splice(0,$scope.caseLawyerNames.length);
        $scope.caseLawyerIds.splice(0,$scope.caseLawyerIds.length);
    });

    // 查询用户信息,设置头像的图片
    $scope.queryUserInfo = function () {
        $rootScope.loadingShow = true;
        $rootScope.fadeShow = true;

        workBarService.queryUserInfo().then(function (response) {
            $rootScope.loadingShow = false;
            $rootScope.fadeShow = false;
            if (response.code == 1) {
                $scope.userName = response.data.username;
                // var tempUrl = httpservice.userHeaderImageUrl + response.data.iconUrl;
                var tempUrl = response.data.iconUrl;
                $scope.myHead = response.data.iconUrl;
              $rootScope.receiveStandsOpen=response.data.authState;
                $scope.headImageUrl = tempUrl;
                $cookies.put('userPortraitSave', $scope.headImageUrl,{
                    expires:expireDate
                });
                $cookies.put('userPortraitName',$scope.userName,{
                    expires:expireDate
                });

                //默认图片显示短名字
                isDefaultHeaderImage();
            }
        }, function (response) {
            $rootScope.loadingShow = false;
            $rootScope.fadeShow = false;
            console.error('queryUserInfo error', response.status, response.statusText);
        });
    };

    // 是否是默认图片
    function isDefaultHeaderImage() {
        // if ($scope.headImageUrl == "img/user_info_head.png"){
        //     $scope.updateShortName($scope.userName);
        //
        //     $(".shortDiv1").show();
        // }
        // else {
        //     $(".shortDiv1").hide();
        // }
        $scope.updateShortName($scope.userName);
    };

    // 无头像时，显示缩写名字
    $scope.updateShortName = function (name) {
        if (name != null || name != "") {
            if (isChinese(name)) {
                var nameSub = name.substr(name.length - 2);
                $scope.userShortName = nameSub;
            } else {
                var nameSub = name.substr(name.length - 5);
                $scope.userShortName = nameSub;
            }
        }
    };

    /**
     * 判断是否为中文
     * @param temp
     * @returns {boolean}
     */
    function isChinese(temp) {
        var re = /[^\u4e00-\u9fa5]/;
        if (re.test(temp)) return false;
        return true;
    }

    // 显示案件下拉列表
    $scope.showCaseList = function () {

        $scope.caseLawyerNames = [];
        $scope.caseLawyers = [];
        $scope.queryCaseList();
    };

    // 查询案件列表
    $scope.queryCaseList = function () {
        $rootScope.loadingShow = true;
        $rootScope.fadeShow = true;
        workBarService.queryCaseList().then(function (response) {
            $rootScope.loadingShow = false;
            $rootScope.fadeShow = false;
            if (response.code == 1) {
                if(!response.data.length){
                  bootbox.dialog({
                    message: "请先创建案件！",
                    title: "提示信息",
                    className:'d-promptBox',
                    buttons: {
                      OK: {
                        label: "确定",
                        className: "d-btn-confirm5",
                        callback: function () {

                        }
                      }
                    }
                  });
                }else{
                  $scope.caseList = response.data;
                }
            }
        }, function (response) {
            $rootScope.loadingShow = false;
            $rootScope.fadeShow = false;
            console.error('queryCaseList error', response.status, response.statusText);
        });
    };

    $scope.chooseTaskCase = function (caseId,caseName) {
        if(caseName.length>13){
          caseName = caseName.substring(0,13)+'...';
        }
        $(".task-caseText").html(caseName);
        $scope.caseSelected = caseId;
        if ($scope.tempCaseName != caseName){
            $scope.tempCaseName = caseName;
            $(".task-stageText").html("请选择");
            $scope.stageSelected = '';
            $scope.stageList = '';
        }
    };

    // 查询案件阶段
    $scope.queryCaseStage = function () {
        if ($scope.caseSelected != "") {
            workBarService.queryCaseStage($scope.caseSelected).then(function (response) {
                if (response.code == 1) {
                    $scope.stageList = response.data;
                    $("#stage-menu").removeClass("fade");
                }
            }, function (response) {
                console.error('queryCaseStage error', response.status, response.statusText);
            });
        } else {
            $("#stage-menu").addClass("fade");
          bootbox.dialog({
            message: "请选择案件！",
            title: "提示信息",
            className:'d-promptBox',
            buttons: {
              OK: {
                label: "确定",
                className: "d-btn-confirm5",
                callback: function () {

                }
              }
            }
          });

           /* bootbox.alert({
              size: "small",
              title: "提示信息",
              message: "请选择案件！",
              className:'d-promptBox',
              callback: function(){ /!* your callback code *!/ }
            });*/
            return;

        }
    };
    $scope.chooseTaskStage = function (stageId,stageName) {
        $scope.stageSelected = stageId;
        $(".task-stageText").html(stageName);


    };

  $(".task-lawyer-list").addClass("hide");
    // $(".task-add").on("click", function () {
    //     $(".task-lawyer-list").removeClass("hide");
    //     $scope.queryCaseLawyer();
    //
    // });
    $scope.showChooseM = function(){
      $(".task-lawyer-list").show();
      $(".task-lawyer-list").removeClass("hide");
      $scope.queryCaseLawyer();
  };
    $scope.delUserLawyer = function(item,index){
      $scope.caseLawyerNames.splice(index,1);
      $scope.caseLawyerIds.splice(index,1);
    }

    $scope.closeLawyerList = function () {
        $(".task-lawyer-list").addClass("hide");
    };

    // 查询案件律师
    $scope.queryCaseLawyer = function () {
        if ($scope.caseSelected != "") {
            $rootScope.loadingShow = true;
            $rootScope.fadeShow = true;
            workBarService.getLawyers($scope.caseSelected).then(function (response) {
                $rootScope.loadingShow = false;
                $rootScope.fadeShow = false;
                if (response.code == 1) {
                    $scope.caseLawyers = [];
                    angular.forEach(response.data, function(data0,index){
                      if ($scope.caseLawyerIds.length > 0) {
                        var flag = false;
                        angular.forEach($scope.caseLawyerIds, function(data1,index){
                          if (data0.lawyerid == data1) {
                            flag = true;
                          }
                        });
                        if (!flag)
                          $scope.caseLawyers.push(data0);
                      } else {
                        $scope.caseLawyers = response.data;
                      }
                    });
                }
            }, function (response) {
                $rootScope.loadingShow = false;
                $rootScope.fadeShow = false;
                console.error('queryCaseLawyer error', response.status, response.statusText);
            });
        } else {
            // alert("请选择案件");
        }
    };

    //添加律师成员
    $scope.addCaseLawyer = function (name, id, icon, index) {
        // if($.inArray(name,$scope.caseLawyerNames) == -1){
        //     var user = {name:name, icon:httpservice.userHeaderImageUrl + icon};
        //
        //   // $scope.caseLawyerNames.push(name);
        //     $scope.caseLawyerNames.push(user);
        // }

        if($.inArray(id,$scope.caseLawyerIds) == -1){
            $scope.caseLawyerIds.push(id);
            var user = {name:name, icon:icon};

            $scope.caseLawyerNames.push(user);
            $scope.caseLawyers.splice(index, 1);
            $('.task-lawyer-list').hide();

        }
        // $(".task-lawyer-list").addClass("hide");
    };


    // 日期选择器
    // form_datetime_panel

    // 保存创建任务

    $scope.saveTask = function () {
        if ($scope.taskContent && $scope.caseSelected && $scope.stageSelected && $scope.taskDate) {

            if ($scope.caseLawyerIds.length > 0) {
                tempLawyerId = $scope.caseLawyerIds.join(",");
            }
            $rootScope.loadingShow = true;
            $rootScope.fadeShow = true;
            workBarService.saveTask($scope.taskContent, $scope.caseSelected, $scope.stageSelected, $scope.taskDate, tempLawyerId,$scope.taskuserName)
                .then(function (response) {
                    $rootScope.loadingShow = false;
                    $rootScope.fadeShow = false;
                    if (response.code == 1) {
                        $("#taskModal").modal('hide');
                    }
                }, function (response) {
                    $rootScope.loadingShow = false;
                    $rootScope.fadeShow = false;
                    console.error('queryCaseLawyer error', response.status, response.statusText);
                });
        } else {
          bootbox.dialog({
            message: "请填写完整信息！",
            title: "提示信息",
            className:'d-promptBox',
            buttons: {
              OK: {
                label: "确定",
                className: "d-btn-confirm5",
                callback: function () {

                }
              }
            }
          });

          /*bootbox.alert({
            size: "small",
            title: "提示信息",
            message: "请填写完整信息！",
            className:'',
            callback: function(){ /!* your callback code *!/ }
          });*/
          return;
        }
    };


    /***新建案件***/
    var namelist = [];

    /*需要引入的html*/
    $scope.userShowTemplateUrl="partials/utolity/bounced.html";

    $scope.isall = 'Created ';

    /*默认为处理中的案件*/
    $scope.pageSize = 15;
    $scope.ctId = "";
    $scope.ccfId = "";
    //新建自然人
    $scope.zname = '';
    $scope.sex = '';
    $scope.phone = '';
    $scope.birthday = '';
    $scope.nationality = '';
    $scope.profession = '';
    $scope.workplace = '';
    $scope.address = '';
    $scope.status = '';
    $scope.remark = '';
    //对方当事人
    // $scope.caseId = 1;
    $scope.caseType = 3;
    $scope.caseClientType = 1;
    $scope.adversaryClientName = '';
    //案由
    $scope.typeId = '';
    $scope.parentId = 0;
    //当事人
    $scope.searchPeoInput = '';
    $scope.CaseFaRenModelInput = '';
    //当事人添加
    $scope.caseZiRanRenModel = '';
    //法人添加
    $scope.caseFrenRenModel = '';
    //查询律师成员
    $scope.keyword = '';
    //处理中、归档案件类型
    $scope.type = '';

    /**用户信息*/
    var DataUser = {};

    //当前用户的名字
    $scope.mSponsor=$cookies.get('userPortraitName');

    //用于替换的名字
    $scope.cacaName= $scope.mSponsor;


    //新建案件相关的参数
    $scope.mNewCase = {
        //案件类别ID
        casetypeid: "",
        //案件类型ID
        CaseClassificationId: "",
        //审理程序ID
        casebusiness: "",
        //案由ID
        casecauseid: "",
        //原告、被告
        UserType: 1,
        //对方当事人类型
        strcaseType: 3,
        //审理程序名称
        ProcedureName: "",
        //弹出框时对应的律师类别
        caselvshitype: "",
        /**律师成员的判断条件*/
        lawyersflost: true,
        /**用户信息*/
        DataUser:{},
        /**律师的框默认不显示*/
        mSolicitorShow:false,
        //**协助律师数组*/
        assistance:new Array()
    };

    //保存新建案件josn
    var jsoncabe;

    //当事人数组和对方当事人数组
    $scope.mMatterPerson = {
        //委托人数组
        Consignor: new Array(),
        //对方当事人数组
        adversaryClients: new Array()
    };

    // var BarristerList = new Array();

    /**律师成员的集合*/
    $scope.lawyers = new Array();

    /**律师成员的判断条件*/
    var lawyersflost = true;

    //保存的时候设置种类
    $scope.mSortShow = {
        /* 案件类别*/
        m1: false,
        /*案件类型*/
        m2: false,
        /*案由*/
        m3: false,
        /*   当事人*/
        m4: false,
        /* 对方当事人*/
        m5: false,
        /* 律师成员*/
        m6: false
    };

    //律师列表需要的初始变量
    $scope.mNoneresultIf=false;

    //案由
    //面包屑里边的名字数组
    $scope.nameList = [];


    /*当前用户的ID*/
    $scope.biglawuserid = kbt.decrypt($cookies.get('cookieUserId'));
    //对方当事人列表
    //$scope.biglawuserid=$stateParams.s_id;
    //自然人列表
    $scope.name = '';
    //法人列表
    $scope.companyname = '';

    //律师成员
    $scope.pageNum = '0';
    $scope.pageSize = '10';
    $scope.pageNow = 1;

    //**协助律师数组*/
    var assistance = new Array();

    /* 新建案件类别, 案件类型, 审理程序接口*/ //-($("#myModal21").height()+50)
    $scope.newXin = function () {
      $('#myModal2').css('display','block');
      $("#myModal21").css({'top':-($(window).height()-54)+'px'}).animate({top:'54px'});
      $rootScope.showCaseDiv = true;
      $("#getSS label input").removeAttr("checked");
      $scope.showModule.addModule = false;
      $scope.caseCateTypeButton(1);
      $scope.createCaseDiv = 1;
      //错误提示
      // $("#textcontent").css('display','none');
      //案由
      $scope.CaseAnyouModel = '';
      //选择团队
      $scope.mNewCase.selectedTeam = "";
      //身份
      $scope.mNewCase.caseclienttype = '';
      //委托人
      $scope.addPerList = [];
      caseBarService.getCaseCategory().then(function (data) {
        if (data.code == 1) {
          $scope.caseCategory = data.data;
        }
        $rootScope.loadingShow = false;
        $rootScope.fadeShow = false;
      }, function () {
        $rootScope.loadingShow = false;
        $rootScope.fadeShow = false;
      });
    };
  $scope.newXinMove=function(){
    $rootScope.newXinToggle=false;
  }
  $rootScope.closeModal = function(){
    // $('#myModal2').hide();
     $('#myModal2').css('display','none');
    $("#myModal21").animate({top:-($(window).height()-44)+'px'});
    $rootScope.showCaseDiv = false;
    setmodaldata();
    // $scope.selectInfo(1, $scope.biglawuserid, "1", "10");
  }

    /**新建案件的多有方法*/
    newCase.textmm($scope,$rootScope,$state,$cookies);

    //调取用户信息
    function getusanme() {
        $rootScope.loadingShow = true;
        $rootScope.fadeShow = true;
        caseBarService.SelectPersonSetInfo($scope.biglawuserid).then(function (data) {
            $rootScope.loadingShow = false;
            $rootScope.fadeShow = false;
            if (data.code == 1) {
                $scope.mNewCase.DataUser = data.data;

            }
        }, function () {
            $rootScope.loadingShow = false;
            $rootScope.fadeShow = false;
        });
    }


    /***退出登录***/
    //跳转详情
    $scope.mOutLogin = function () {
        $state.go("index");
        $cookies.remove('PwdBenDi');
        //$cookies.remove('userIdBenDi');
        $cookies.remove('userIdBenDiFilter');
        $rootScope.ws.close();
    };



    /*初始化函数*/
    $scope.init();


    //function showNotice(msg){
    //    var Notification = window.Notification || window.mozNotification || window.webkitNotification;
    //    if(Notification){
    //        Notification.requestPermission(function(status){
    //            //status默认值'default'等同于拒绝 'denied' 意味着用户不想要通知 'granted' 意味着用户同意启用通知
    //            if("granted" != status){
    //                return;
    //            }else{
    //                var tag = "sds"+Math.random();
    //                var notify = new Notification(
    //                    "您有一条新的消息",
    //                    {
    //                        dir:'auto',
    //                        lang:'zh-CN',
    //                        tag:tag,//实例化的notification的id
    //                        icon:'img/logo-page.png',//通知的缩略图,//icon 支持ico、png、jpg、jpeg格式
    //                        body:msg //通知的具体内容
    //                    }
    //                );
    //                notify.onclick=function(){
    //                    //如果通知消息被点击,通知窗口将被激活
    //                    window.focus();
    //                },
    //                    notify.onerror = function () {
    //                    };
    //                notify.onshow = function () {
    //                    setTimeout(function(){
    //                        notify.close();
    //                    },10000)
    //                };
    //                notify.onclose = function () {
    //                };
    //            }
    //        });
    //    }else{
    //    }
    //};
    //
    //$scope.getWebSocket = function () {
    //
    //    workBarService.getWebSocket().then(function (data) {
    //        if(data.code == 1){
    //
    //            for(var i=0;i<data.data.length;i++){
    //                showNotice(data.data[i].content);
    //            }
    //        }
    //    });
    //}
    //
    //setInterval($scope.getWebSocket,60000);
    //轮训获取返回的值弹出,websocekt---------------结束------------------------


  //案件任务进程面板
  /*登录ID*/
  $scope.loginId = kbt.decrypt($cookies.get('cookieUserId'));
  $scope.type = $cookies.get('type');
  //   //获取点击的案件的id
  // var caseId = $cookies.get('caseAppId');
  //获取点击的案件的id
  // var caseId = $cookies.get('caseAppId');
  //登录用户的ID
  var userId = kbt.decrypt($cookies.get('cookieUserId'));
  //获取点击的案件的type
  $scope.type = $cookies.get('type');
  //当前用户的名字
  $scope.userName=$cookies.get('userPortraitName');
  //taskId
  $scope.detailTaskId = '';
  //大的列表
  $scope.digList = '';
  //详情
  $scope.detailList = '';//用户信息乱码七招的
  $scope.detailAll = '';//详情信息
  $scope.logList = '';//日志
  $scope.plList = '';//评论
  $scope.fileList = ""; //文件

  //律师的列表
  $scope.lawyersList = '';

  //详情评论
  $scope.commentInput = '';


  var startArr = new Array();


  $(function() {
   $("#sortable").sortable({
   connectWith: ".CaseDrag",
   items :"li",                        //只是li可以拖动
   opacity: 0.4,                       //拖动时，透明度为0.4
   revert: true,                       //释放时，增加动画
   start: function(event, ui) {
   startArr = [];
   //获取条目id
   $scope.uiitemid = ui.item.attr('id');
   // var strs = new Array(); //定义一数组
   // strs = $scope.uiitemid; //字符分割
   var s = document.getElementById($scope.uiitemid);
   var par = s.parentNode;   //得到s的父节点

   //获取阶段id
   $scope.nameid = $(par).eq(0).attr('id');
   var arr = $(par).eq(0)[0].children;
   var startSequence = 1;
   for (var i = 0; i < arr.length; i++) {
   if($.isNumeric(arr[i].id) && arr[i].id != $scope.uiitemid){
   var startObj = {
   caseStageId: $scope.nameid,
   taskId: arr[i].id,
   sequence: startSequence,
   };
   startSequence++;
   }else{
   continue;
   }

   startArr.push(startObj);
   }
   },
   out:function (event, ui) {
   $scope.targetid=event.target.id;
   $scope.uiitemid=ui.item.attr('id');
   },
   stop:function (event, ui) {
   //获取条目id
   // $scope.uiitemid = ui.item.attr('id');
   // var strs = new Array(); //定义一数组
   // strs = $scope.uiitemid.split("!%!"); //字符分割
   var s = document.getElementById($scope.uiitemid);
   var par = s.parentNode;   //得到s的父节点

   //获取阶段id
   $scope.nameid = $(par).eq(0).attr('id');
   var arr = $(par).eq(0)[0].children;
   var stopSequence = 1;
   for (var i = 0; i < arr.length; i++) {
   if($.isNumeric(arr[i].id)){
   var stopObj = {
   caseStageId: $scope.nameid,
   taskId: arr[i].id,
   sequence: stopSequence,
   };
   stopSequence++;
   }else{
   continue;
   }

   startArr.push(stopObj);

   }

   //  调用接口排序 暂时注调
   //   $scope.returnlistid( $scope.targetid, $scope.uiitemid);
   $scope.returnlistid(startArr);
   }

   }).disableSelection();


   });


  $scope.init = function () {
    /*如果是归档案件不可编辑11*/
    if($scope.type==7){

      $('#shuxieqisu').hide();//诉讼请求
      $('#shuxieqisu-hide').hide();//诉讼请求


      $('#detailcheckbox').attr('disabled',true);
    }
    /*用于固定导航条*/
    sessionStorage.navNum = 1;

  };


  $scope.init();

  //解决火狐冲突
  $scope.getFireFocus = function () {
    $('.getFireFocus').focus();
  };

  //排序完成请求网络
  $scope.returnlistid = function (startArr) {
   $rootScope.loadingShow = true;
   $rootScope.fadeShow = true;
   caseBarDetailjinchengService.getsortsortable(startArr).then(function (data) {
   if (data.code == 1) {

   }
   $rootScope.loadingShow = false;
   $rootScope.fadeShow = false;
   }, function (response) {
   $rootScope.loadingShow = false;
   $rootScope.fadeShow = false;
   console.error('updatemessage error', response.status, response.statusText);
   });
   };



  //获取列表---进程
   $scope.getList = function(){
     $rootScope.loadingShow = true;
     $rootScope.fadeShow = true;
     caseBarDetailjinchengService.getList($cookies.get('caseAppId')).then(function (data) {
     $rootScope.loadingShow = false;
     $rootScope.fadeShow = false;
     if(data.code == 1){
          $scope.bigList = data.data;



       }
     });
   };
   // $scope.getList();

  //添加任务
 /* $scope.addTask = function (allList,inputText) {
    console.log(allList,inputText)
   if(inputText != ''){
   $rootScope.loadingShow = true;
   $rootScope.fadeShow = true;
   //inputText,caseId,allList.stageId,null,$scope.loginId,$scope.userName
   var params = {
   "caseId":caseId,
   "caseStageId":allList.stageId,
   "title":inputText,
   "deadLine":allList.deadline,
   "executorId":allList.executorId,//进程id
   "panelId":allList.panelId//工作台的i
   };
   caseBarDetailjinchengService.addTask(params).then(function (data) {//inputText,caseId,allList.stageId,null,$scope.loginId,$scope.userName
   $rootScope.loadingShow = false;
   $rootScope.fadeShow = false;
     console.log(data)
   if(data.code == 1){
     console.log('添加任务')
   $scope.getList();
   $('.zqNewGreat').css('display','none');
   }
   })
   }

   };*/

  $scope.executors = {};

  //点击P标签,出现详情界面 估计可以删
  $scope.caseDetailShow = function(taskId){
    // var taskId = task.id;
    // if($scope.taskType == 1){
      // if($('.rightComeTo').css('right')!='0px'){
        //   $('.rightComeTo').css('right','-700px');
        //   $('.rightComeTo').animate({
        //     "right": "0"
        //   }, 300);
      // }

      $('.textareaAndSaveBox').addClass('hide');
      $('#shuxieqisu').removeClass('hide');
      $('#jqisuzhunbei').removeClass('hide');
      $('#jqisuzhunbei1').addClass('hide');
      $('.LawyerAddBody').addClass('hide');
      $scope.detailTaskId = taskId;
      caseBarDetailjinchengService.getDetailList(taskId).then(function (data) {

        if(data.code == 1){

          // $scope.caseId = data.data.task.caseid;
          $scope.detailList = data.data.task;
          $scope.detailAll = data.data;

          $scope.plList = data.data.caseTaskReviews;
          $scope.executors = data.data.taskExecutors;
          $scope.logList = data.data.taskLogs;
          $scope.fileList = data.data.caseTaskAttses;
          $scope.checkList = data.data.caseTaskCheckList;
          $scope.caseStageName = data.data.task.caseStage.name;

          if($scope.checkList == ''){
            $scope.showCheckItem.taskCheckPage = false;
          }else {
            $scope.showCheckItem.taskCheckPage = true;
          }

          //更新列表数据
          refreshTaskListByState(1);
          refreshProgressBar();

          //设置详情的复选框是否选中
          // var $cheackBox = $(cheackBox);
          // var cheackBox = $event.target;
          if($scope.detailList.status == "1"){
            $('#detailcheckbox').prop("checked",true);
            // $('#detailcheckbox').checked = true;
            $('.title').css({
              'text-decoration':'line-through',
              'color':'#00BB9C'
            });
            $('.taskShade').css('display','block');
          }else {
            $('#detailcheckbox').prop("checked",false);
            // $('#detailcheckbox').checked =false;
            $('.title').css({
              'text-decoration':'none',
              'color':'#999'
            });
            $('.taskShade').css('display','none');
          }

        }
      });
  };

  $scope.caseDetailShow2 = function(taskId){
    // var taskId = task.id;
    // if($scope.taskType == 1){
    // if($('.rightComeTo').css('right')!='0px'){
    $('.rightComeTo').css('right','-700px');
    $('.rightComeTo').animate({
      "right": "0"
    }, 300);
    // }
    $scope.caseDetailShow(taskId);
  };


  //删除进程任务task
  $scope.deteleTask = function () {
    $('#jcdeletedeleteModalpanel').modal('show');
    $('.rightComeTo').animate({
      "right": "-700"
    }, 300);
  };

  //删除进程
  $scope.jcdeleteupdateNameConfirm = function () {
    $rootScope.loadingShow = true;
    $rootScope.fadeShow = true;
    caseBarDetailjinchengService.updateTask($scope.detailTaskId,"9",$scope.detailList.title,$scope.loginId,$scope.detailList.caseid,$scope.userName).then(function (data) {
      $rootScope.loadingShow = false;
      $rootScope.fadeShow = false;
      if(data.code == 1){
       refreshTaskListByState(1);
       refreshTaskListByState(2);
       //关闭进程confirm弹窗
        $('#jcdeletedeleteModalpanel').modal('hide');
      }
    })
  };
  //删除截至日期

  $scope.deleteTaskDeadLine = function (item,$event) {
    if($rootScope.typeIf!=7){
      var params={
        "taskId":item.id,
        "caseId":item.caseid
      };
      bootbox.dialog({
        message: "确定要删除截至日期",
        title: "提示信息",
        className:'d-promptBox',
        buttons: {
          OK: {
            label: "确定",
            // className: "btn-default",
            // className: "btn-confirm",
            // confirmButtonColor: "#DD6B55",
            className: "d-btn-confirm",
            callback: function () {
              workBarService.deleteTaskDeadLine(params).then(function (data) {
                if(data.code == 1){
                  $scope.detailList.deadline = null;
                  refreshTaskListByState(1)
                  refreshTaskListByState(2)

                }
              })
            }
          },
          Cancel: {
            label: "取消",
            // className: "btn-default",
            // className: "btn-cancel",
            // confirmButtonColor: "#DD6B55",
            className: "d-btn-cancel",
            callback: function () {
            }
          }
        }
      });

    }

    $event.stopPropagation();
  };



  //点击复选框.出现横线
  $scope.throthTheP = function ($event,id,title,caseid) {

    var cheackBox = $event.target;
    var $cheackBox = $(cheackBox);

    if(cheackBox.checked){
      $($cheackBox).siblings('.boxRight').children('p').css({
        'text-decoration':'line-through',
        'color':'#00BB9C'
      });
      caseBarDetailjinchengService.updateTask(id,"1",title,$scope.loginId,caseid,$scope.userName).then(function (data) {
        if(data.code == 1){
          $scope.getList();
        }
      });
    }else {
      $($cheackBox).siblings('.boxRight').children('p').css({
        'text-decoration':'none',
        'color':'black'
      });
      caseBarDetailjinchengService.updateTask(id,"0",title,$scope.loginId,caseid,$scope.userName).then(function (data) {
        $rootScope.loadingShow = false;
        $rootScope.fadeShow = false;
        if(data.code == 1){
          $scope.getList();
        }
      });
    }
  };

  //点击详情界面的复选框 估计可以删
  $scope.detailThrothTheP = function ($event,id1) {
    var cheackBox = $event.target;
    var $cheackBox = $(cheackBox);
    // event.stopPropagation();
    $('.rightComeTo').css('right','0px');
    $rootScope.loadingShow = true;
    $rootScope.fadeShow = true;
    if(cheackBox.checked){
      $($cheackBox).siblings('.title').css({
         'text-decoration':'line-through',
         'color':'#00BB9C'
      });
      $($cheackBox).parents('div[id=half1]').siblings('#half').find('span.title').css({
        'text-decoration':'line-through',
        'color':'#00BB9C'
      })

      caseBarDetailjinchengService.updateTask(id1,"1",$scope.detailList.title,$scope.loginId,$scope.detailList.caseid,$scope.userName).then(function (data) {
        $rootScope.loadingShow = false;
        $rootScope.fadeShow = false;
        if(data.code == 1){
          $scope.getList();
          // $scope.other.myTasks.splice(index,1);
          // $scope.overTaskList.unshift(t);

          //刷新详情
          // $scope.caseDetailShow($scope.detailTaskId);
          $('.taskShade').css('display','block');

          $scope.tashDetailPara.task.task.status=1;

          // 删除工作台对应任务
          $scope.$broadcast('refreshTashStatus', $scope.tashDetailPara);

          //案件进程
          $scope.$broadcast('refreshCaseTask', $scope.tashDetailPara);
          // 详情页关闭，目前解决不了多次点选详情页的完成checkbox，退而求其次
          $('.rightComeTo').css("right",'-700px');

        }
      });
    }else {
      caseBarDetailjinchengService.updateTask(id1,"0",$scope.detailList.title,$scope.loginId,$scope.detailList.caseid,$scope.userName).then(function (data) {
        $rootScope.loadingShow = false;
        $rootScope.fadeShow = false;
        if(data.code == 1){
          $scope.getList();
          //刷新详情
          // $scope.caseDetailShow($scope.detailTaskId);
          $($cheackBox).siblings('.title').css({//.children('p')
            'text-decoration':'none',
            'color':'#999'
          });

          $($cheackBox).parents('div[id=half1]').siblings('#half').find('span.title').css({
            'text-decoration':'none',
            'color':'#999'
          })
          $('.taskShade').css('display','none');
          $scope.tashDetailPara.task.task.status=0;
          // 回退至工作台任务
          $scope.$broadcast('refreshUnfinishTashStatus', $scope.tashDetailPara);
          //案件进程
          $scope.$broadcast('refreshCaseTask', $scope.tashDetailPara);
        }
      });
    }
  };

  //更新详情描述updateDes(desInputText,detailList.title)可以删
  $scope.updateDes = function () {
    // event.stopPropagation();
    var params = {
      "taskId":$scope.detailTaskId,
      "content": $scope.detailList.content,
      "deadLine":$scope.detailList.deadline,
      "title":$scope.detailList.title,
      "creatorId":$scope.loginId,
      "caseId":$cookies.get('caseAppId'),
      "userName":$scope.userName,
      "estimateHour":$scope.detailList.estimateHour,
      'actualHour':$scope.detailList.actualHour
    };
    caseBarDetailjinchengService.updateDateOrDes(params).then(function (data) {
      //$scope.detailTaskId,null,$scope.date,$scope.detailList.title,$scope.loginId,$scope.detailList.caseid,$scope.userName
      $rootScope.loadingShow = false;
      $rootScope.fadeShow = false;
      if(data.code == 1){
        $('.textareaAndSaveBox').addClass('hide');
        $('#shuxieqisu').removeClass('hide');
        $('#jqisuzhunbei').removeClass('hide');
        $('#jqisuzhunbei1').addClass('hide');
        //刷新详情
        $scope.caseDetailShow($scope.detailTaskId);

        //刷新列表
        // $scope.getList();


      }
    });
  };

  // $scope.$watch('detailList.title', function(newValue, oldValue) {
  //   $rootScope.bigList[0].taskList.push(newValue);
  // },true);

  //获取律师列表---任务进程可以删
  $scope.showAddPeopleBox = function () {
    $(".LawyerAddBody").removeClass('hide').show();
    caseBarDetailjinchengService.getLawyers($cookies.get('caseAppId'),$scope.detailTaskId).then(function (data) {
      if(data.code == 1){
        $scope.lawyersList = data.data;
      }
    });
  };

  //添加任务律师执行人
  $scope.addTaskLawyer = function (index,lawyerId,lawyerName) {
    caseBarDetailjinchengService.addTaskLawyer($scope.detailTaskId,lawyerId,lawyerName,$scope.loginId,$scope.userName,$cookies.get('caseAppId')).then(function (data) {
      if(data.code == 1){
        $scope.caseDetailShow($scope.detailTaskId);
        $(".LawyerAddBody").addClass('hide');
        $('.task-lawyer-list').hide();
      }

    },function (response) {
      $rootScope.loadingShow = false;
      $rootScope.fadeShow = false;
      console.error('addTaskLawyer error', response.status, response.statusText);
    });
  };

  //删除任务律师执行人
  $scope.deleteTaskLaywer = function (lawyerId,executiveid,executiveName,taskid) {
    // $rootScope.loadingShow = true;
    // $rootScope.fadeShow = true;
    bootbox.dialog({
      message: "确定删除?",
      title: "提示信息",
      className:'d-promptBox',
      buttons: {
        OK: {
          label: "确定",
          className: "d-btn-confirm",
          callback: function () {
            caseBarDetailjinchengService.deleteTaskLawyer(lawyerId,$scope.loginId,$scope.userName,executiveid,executiveName,taskid).then(function (data) {
              // $rootScope.loadingShow = false;
              // $rootScope.fadeShow = false;
              if(data.code == 1){
                $scope.caseDetailShow($scope.detailTaskId);
              }
            },function (response) {

            });
          }
        },
        Cancel: {
          label: "取消",
          className: "d-btn-cancel",
          style:'background:red',
          callback: function () {

          }
        }

      }
    });
      $rootScope.loadingShow = false;
      $rootScope.fadeShow = false;
      // console.error('deleteTaskLawyer error', data.status, data.statusText);
  };


  //发评论--案件进程
  $scope.sendComment = function (text) {
    $rootScope.loadingShow = true;
    $rootScope.fadeShow = true;
    caseBarDetailjinchengService.sendJCComment($scope.loginId,text,$scope.detailTaskId).then(function (data) {
      $rootScope.loadingShow = false;
      $rootScope.fadeShow = false;
      if(data.code == 1){
        //刷新详情
        $scope.caseDetailShow($scope.detailTaskId);
        $scope.commentInput = '';
        //刷新列表
        // $scope.getList();
      }
    })
  };

  // 任务日志
  $scope.getTaskLogList = function () {
    caseBarDetailjinchengService.getTaskLog($scope.detailTaskId).then(function (response) {
      if(response.code == 1){
        $scope.logList = response.data;
      }
    },function (response) {
      console.error('getTaskLogList error', response.status, response.statusText);
    })
  };

  //附件上传--进程任务
  $('.appendix-input').change(function () {
      if($rootScope.type != 7){
        var fileData = new FormData();
        fileData.append('filename1',this.files[0]);
        fileData.append('taskId',$scope.detailTaskId);
        fileData.append('creatorId',$scope.loginId);
        $rootScope.loadingShow = true;
        $rootScope.fadeShow = true;
        caseBarDetailjinchengService.uploadAppendix(fileData).then(function (response) {
          $rootScope.loadingShow = false;
          $rootScope.fadeShow = false;
          if (response.code == 1) {
            //刷新详情
            // $scope.caseDetailShow($scope.detailTaskId);
            var item = {
              'creatUserId':response.data.creatUserId,
              'id':response.data.id,
              'taskId':response.data.taskId,
              'fileSize':response.data.fileSize,
              'fileName':response.data.fileName,
              'filePath':response.data.filePath,
            };
            $scope.fileList.push(item);
            $(".appendix-input").val("");
            refreshTaskListByState(1);
          }
        }, function (response) {
          $rootScope.loadingShow = false;
          $rootScope.fadeShow = false;
          console.error('uploadAppendix error', response.status, response.statusText);
        });
      }
    });

  $scope.showFileSuffix = function (fileName) {
    var suffix = "";
    if(fileName){
      var str= fileName.split(".");
      suffix = str[str.length-1];
      suffix = suffix.toLowerCase();
      var fileTypeList = [ 'xlsx' , 'doc' , 'html' , 'jpg', 'pdf' , 'png' , 'ppt' , 'txt' , 'xls' , 'docx'];
      if(fileTypeList.indexOf(suffix) == -1){
        suffix = "empty";
      }
    }
    return suffix;
  };

  // 附件下载---进程
  $scope.downloadFileProgress = function (file) {
    /*taskId
     taskAttachedId*/
    var params = {'caseId':$cookies.get('caseAppId'),'taskId':$scope.detailTaskId,'taskAttachedId':file.id};
    caseBarDetailjinchengService.downloadAppendix(params).then(function (response) {
      var fileData = new Blob([response.data]);
      var link = document.createElement('a');
      link.href = URL.createObjectURL(fileData);
      link.download = file.fileName;
      link.click();
      // window.URL.revokeObjectURL(link.href);
    });
  };

  // 删除附件
  $scope.deleteTaskAppendix = function (fileId,fileName,createrId) {
    if($rootScope.typeIf!=7){
      bootbox.dialog({
        message: '确定要删除'+fileName+'附件吗',
        title: "提示信息",
        className:'d-promptBox',
        buttons: {
          OK: {
            label: "确定",
            className: "d-btn-confirm",
            callback: function () {
              caseBarDetailjinchengService.deleteTaskAppendix(fileId,fileName,$scope.detailTaskId,createrId).then(function (data) {
                if(data.code == 1){
                  $scope.caseDetailShow($scope.detailTaskId);
                }
              },function (response) {
                console.error('deleteTaskAppendix error', response.status, response.statusText);
              });
            }
          },
          Cancel: {
            label: "取消",
            className: "d-btn-cancel",
            callback: function () {

            }
          }

        }
      });
    }


  };


  //点击新增
  $scope.showAddBox = function ($event) {
    var $a = $($event.target);
    $($a).parents('.newAdd').siblings('.zqNewGreat').css('display','block');
  };

  //点击取消
  $scope.addCancelBtn = function ($event) {
    var $cancel = $($event.target);
    $($cancel).parents('.zqNewGreat').css('display','none');
  };

  //点击新增
  //$('.newAdd').click(function(){
  //    $(this).siblings('.zqNewGreat').toggle();
  //});
  //新增后的取消按钮
  //$('.cancel').click(function () {
  //    $(this).parents('.zqNewGreat').css('display','none');
  //});

  //点击P标签出现详情界面
  // $('.caseDetailShow').click(function () {
  //    $('.rightComeTo').animate({
  //        "right": "0"
  //    }, 300);
  // });

  $('.closeDetail').click(function(){
    $(this).parents('.rightComeTo').animate({
      "right": "-700"
    }, 300);
    $('.LawyerAddBody').addClass('hide');
  });

  //P标签点击添加任务
  $('.addTaskPClick').click(function (event) {
    event.stopPropagation();
    if($rootScope.typeIf!=7){
      $('#shuxieqisu').addClass('hide');
      $('.textareaAndSaveBox').removeClass('hide');
      $('#jqisuzhunbei1').removeClass('hide');
      $('#jqisuzhunbei').addClass('hide');
    }


  });

  //点击任务的名字,出现编辑
  $('.jtitleName').click(function () {
    getType();
    if ($rootScope.typeIf!=7) {
      $('#shuxieqisu').addClass('hide');
      $('.textareaAndSaveBox').removeClass('hide');

      $('#jqisuzhunbei1').removeClass('hide');

      $('#jqisuzhunbei').addClass('hide');
    }else{
      $('#jqisuzhunbei1').addClass('hide');
    }
  });
  //点击取消,显示P标签
  $('.addTaskCancelBtn').click(function (event) {
    event.stopPropagation();
    $('.textareaAndSaveBox').addClass('hide');
    $('#shuxieqisu').removeClass('hide');
    $('#jqisuzhunbei').removeClass('hide');
    $('#jqisuzhunbei1').addClass('hide');
  });


  //添加任务人
  /*=====添加律师成员=======*/
  //点击出现BOX
  //$('.showAddPeopleBox').click(function () {
  //    $(".LawyerAddBody").toggle();
  //
  //});
  $(".LawyerList li").on("click",function(){
    var i = $(this).index();
    $(this).addClass("active").siblings().removeClass("active");
    $(this).parent().siblings(".LawyerDiv").find(".Lawyerbox").addClass("hide");
    $(this).parent().siblings(".LawyerDiv").find(".Lawyerbox").eq(i).removeClass("hide");
  });
  $(".LawyerAddBody .Add-close").on("click",function(){
    $(".LawyerAddBody").addClass('hide');
  });

  //底部的评论之类的
  $('.pl').click(function () {
    $(this).addClass('clickActive');
    $(this).siblings().removeClass('clickActive');

    $('.plDiv').css('display','block');
    $('.rwrzDiv').css('display','none');

    $('#half2').css('display','block');
  });
  $('.rwrz').click(function () {
    $(this).addClass('clickActive');
    $(this).siblings().removeClass('clickActive');

    $('.rwrzDiv').css('display','block');
    $('.plDiv').css('display','none');

    $('#half2').css('display','none');
  });


  $('.bigBody').click(function () {

    if($('.rightComeTo').css('right')=='0px'){

      $('.rightComeTo').animate({
        "right": "-700"
      }, 300);
    }
  });

  //检查项
  $scope.showCheckItem = {
    CheckItem:false,
    addCheckItem:true,
    delCheckItem:false,
    editCheckItem:false,
    taskCheckPage:false,//任务检查项
  };
  $scope.showCheckItem.CheckItem = false;
  $scope.showCheckItem.addCheckItem = true;
  //打开检查项--进程
  function openCourseCheckitem() {
    $scope.showCheckItem.CheckItem = false;
    $scope.showCheckItem.addCheckItem = true;
    $scope.showCheckItem.taskCheckPage = true;
    refreshProgressBar();
  }
  //添加检查项
  function addCheckItem() {
    $scope.showCheckItem.CheckItem = !$scope.showCheckItem.CheckItem;
    $scope.showCheckItem.addCheckItem = false;
    // $('#checkName').focus();

  }

  //取消
  function cancelCheckItem() {
    $scope.showCheckItem.CheckItem = false;
  }
  //编辑检查项
  function editChecked(checkObj,$event) {
    if($rootScope.typeIf!=7){
      checkObj.showEditCheck = !checkObj.showEditCheck;
    }

  }

  //删除检查项
  function checkItemDel() {
    $scope.showCheckItem.CheckItem = false;
    $scope.showCheckItem.addCheckItem = true;
    if($scope.evidenceCheckList.length == 0){
        $scope.evidenceCheckItem = false;
        $scope.evidenceCheck.checkname = '';
    }
    if($scope.checkList.length == 0){
        $scope.showCheckItem.taskCheckPage = false;
        $scope.taskCheck.checkname = '';
    }
  }

  $scope.saveTaskCheckedItem = saveTaskCheckedItem;
  $scope.updateTaskCheckedItem = updateTaskCheckedItem;
  $scope.openCourseCheckitem = openCourseCheckitem;
  $scope.addCheckItem = addCheckItem;
  $scope.cancelCheckItem = cancelCheckItem;
  $scope.checkItemDel = checkItemDel;
  $scope.delCheckItem = delCheckItem;
  $scope.editChecked = editChecked;
  $scope.changeCheckListStatus = changeCheckListStatus;

  //保存进程  接口--检查项
  $scope.taskCheck = {};
  function saveTaskCheckedItem() {
    var params = {"taskId":$scope.detailTaskId,"checkName":$scope.taskCheck.checkname};
    caseBarDetailjinchengService.saveTaskCheckedItem(params).then(function (response) {
      if(response.data.code == 1){
        $scope.showCheckItem.CheckItem = false;
        $scope.showCheckItem.addCheckItem = true;

        var item = {
          "checkname":$scope.taskCheck.checkname,
          "id":response.data.data.id,
        };
        $scope.checkList.push(item);
        //刷新进度条
        refreshProgressBar();
        //刷新检查项列表
        // $scope.caseDetailShow();
        refreshTaskListByState(1);
      }
      $scope.showCheckItem.CheckItem = false;
      $scope.showCheckItem.addCheckItem = true;
      $scope.taskCheck.checkname = '';
    });
  }

  function changeCheckListStatus(checkObj) {
    switch (checkObj.status){
      case 1: checkObj.status = 5;
        break;
      case 5: checkObj.status = 1;
        break;
      case undefined: checkObj.status = 5;
        break;
    }
    refreshProgressBar(checkObj);
    updateTaskCheckedItem(checkObj);
  }

  //案件进程  接口---更新
  function updateTaskCheckedItem(checkObj) {

    //刷新进度条
    refreshProgressBar();

    var params = {"caseTaskCheckId":checkObj.id,"checkStatus":checkObj.status,"taskId":$scope.detailTaskId,"checkName": checkObj.checkname};
    caseBarDetailjinchengService.updateTaskCheckedItem(params).then(function (response) {
      checkObj.showEditCheck= false;
      if (response.data.code == 1) {

      }
    })
  }

  function refreshProgressBar() {
    var checked = 0;
    for(var i=0;i<$scope.checkList.length;i++) {
      if ($scope.checkList[i].status == 5) {
        checked++;
      }
    }
    $scope.checkList.checkedList = checked;

    if(checked.status != 5){
      $('.L_progressBaring').css({
        "width":(checked/$scope.checkList.length)*402+'px',
        'height':'10px',
        'background':'#00bfb5',/*#e6e6e6*/
        'border-radius':'10px',
        '-webkit-transition':'width 2s',  /* Safari and Chrome */
        '-moz-transition':'width 2s',  /* Firefox  */
        '-o-transition':'width 2s',  /* Opera */
      });

    }
    // else if(checked.status == undefined){
    //   $('.L_progressBaring').css({
    //     "width":(checked/$scope.checkList.length)*402+'px',
    //     "height":'10px',
    //     'background':'#e6e6e6',
    //     'border-radius':'10px',
    //     '-webkit-transition': 'width 2s',  /* Safari and Chrome */
    //     '-moz-transition':'width 2s',  /* Firefox  */
    //     '-o-transition':'width 2s'  /* Opera */
    //   })
    // }
  }

  //删除--检查项
  function delCheckItem(index,checkObj) {
    var params = {"caseTaskCheckId":checkObj.id,"taskId":$scope.detailTaskId,"checkStatus":9};
    caseBarDetailjinchengService.updateTaskCheckedItem(params).then(function (response) {
      if(response.data.code == 1){
        $scope.checkList.splice(index,1);
        //刷新进度条
        refreshProgressBar();
          if($scope.checkList.length == 0){
              $scope.showCheckItem.taskCheckPage = false;
          }
        checkObj.showEditCheck = false;
        refreshTaskListByState(1);
      }
    });
  }
  //案件进程--附件预览
  $scope.taskAttach = false;
  $scope.taskPreviewAttach = function (file) {
    $('#myModalTaskPreview').modal('show');

      var fileName = file.fileName || file.name;
      var suffix = "";
      if(fileName){
          var str= fileName.split(".");
          suffix = str[str.length-1];
          suffix = suffix.toLowerCase();
          var fileTypeList = [ 'jpg', 'pdf' , 'png','JPG', 'PDF' , 'PNG'  ];
          if(fileTypeList.indexOf(suffix) != -1){
              // 清空上次信息
              // pdfDelegate.$getByHandle('my-pdf-container').load();
              // $('.y-preview-img2').attr('src','');

              if (suffix != 'pdf') {
                $('#pdfViewerCanvas').hide();
                $('.y-preview-img2').show();
              } else {
                $('#pdfViewerCanvas').show();
                $('.y-preview-img2').hide();
              }

              $('.y-preview').attr('data-toggle','modal');
              $('.y-preview').attr('data-target','#myModalTaskPreview');
              var params = {'caseId':$scope.detailList.caseid,'taskId':$scope.detailTaskId,'taskAttachedId':file.id};
              caseBarDetailjinchengService.taskPreviewAttach(params).then(function (response) {
                  var fileData = new Blob([response.data]);
                  var link = URL.createObjectURL(fileData);
                  $scope.taskAttach = true;
                  if (suffix != 'pdf') {
                    $rootScope.preViewHref = link;
                  }
                  else
                    pdfDelegate.$getByHandle('my-pdf-container').load(link);
                  // window.URL.revokeObjectURL(link);
              })
          }else {
              $('.y-preview').attr('data-toggle',' ');
              $('.y-preview').attr('data-target',' ');
              bootbox.dialog({
                  message: "此文件类型不支持预览",
                  title: "提示信息",
                  className:'d-promptBox',
                  buttons: {
                    OK: {
                    label: "确定",
                    className: "d-btn-confirm",
                    callback: function () {

                    }
                  },
                      Cancel: {
                          label: "取消",
                          className: "d-btn-cancel",
                          callback: function () {

                          }
                      }
                  }
              });
          }
      }

  };
  //案件进程--关闭预览
  $scope.taskPreviewAttachClose = function () {
    $scope.taskAttach = false;
    window.URL.revokeObjectURL($scope.preViewHref);
  };

  //证据清单面------------------------------------------------------------------证据
      /*登录ID*/
    $scope.loginId = kbt.decrypt($cookies.get('cookieUserId'));
    //获取点击的案件的type
  function getType(){
    $scope.type = $cookies.get('type');

  }
  getType()

    //去用户的名字
    $scope.userPortraitName=$cookies.get('userPortraitName');

    //证据类型列表,搜索前边的
    $scope.ETypeList = '';

    //获取证据组列表接口
    $scope.EGroupList = '';
    //证据组的名字
    $scope.EGName = '';
    //证据组的描素
    $scope.EGDescription = '';
    //删除证据组的ID
    $scope.deleteEGroupId = '';

    //获取证据池列表接口
    // $scope.EPollList = '';

    //添加证据组
    $scope.addEGText = '';
    $scope.addEGTitle = '';
    //快速创建
    $scope.quickAddInput = '';

    //证据组ID
    $scope.evidenceGroupId = '1';
    //修改证据组的id
    $scope.updateGroupId = '';
    //证据的ID
    $scope.evidenceID = '';
    //证据清单
    $scope.eInventory = '';

    //详情
    $scope.detailUser = '';//图片
    $scope.detailFJ = '';//下载的附件
    $scope.detailData = '';//data
    $scope.detailEGName = '';//证据组名字
    $scope.veiHeaderImageUrl = '';//头像
    //修改证据组的名字
    $scope.updateEGName = '';
    $scope.clickLi = '';

    //评论
    $scope.plData = '';
    //日志
    $scope.zrData = '';
    //发送评论
    $scope.commentInput = '';
    //详情修改详情
    $scope.updateDetailXInput = '';
    //详情修改备注
    $scope.updateDetailBInput = '';

    //记录是重命名还是添加证据组
    $scope.addOrUpdataName = '1';//1是添加,2是重命名

    //获取的律师的成员
    $scope.CaseLawyerTianSelect = '';

    //添加律师成员的taskId
    $scope.addLSTaskId = '';
    //未分组证据
    $scope.evidenceNot = true;
    //证据面板检查项
    $scope.attachmentEvidence = false;

    $scope.caseAppName = $cookies.get('caseAppName');

    //证据检查项
    $scope.evidenceCheckItem = false;
    $scope.openEvidenceCheckitem = function () {
      $scope.evidenceCheckItem = true;
    };

    //获取证据类型列表,搜索前边的
    $scope.getETypeList = function () {
      caseBarDetailZhengService.getETypeList().then(function (data) {
        if (data.code == 1) {
          $scope.ETypeList = data.data;
        }
      })
    };
    $scope.getETypeList();

    //获取证据组列表接口
  $scope.getEGroupList = function () {
    $rootScope.loadingShow = true;
    $rootScope.fadeShow = true;
    caseBarDetailZhengService.getEGroupList($cookies.get('caseAppId')).then(function (data) {
      $rootScope.loadingShow = false;
      $rootScope.fadeShow = false;
      if (data.code == 1) {
        $scope.EGroupList = data.data;
      }
    })
  };

    //添加证据组或者修改证据组名字
  $scope.addEGroup = function () {

    if ($scope.addOrUpdataName == '1') {

      $rootScope.loadingShow = true;
      $rootScope.fadeShow = true;
      //添加
      caseBarDetailZhengService.addEGroup($cookies.get('caseAppId'), $scope.addEGText, $scope.addEGTitle, $scope.loginId).then(function (data) {
        if (data.code == 1) {

          //刷新证据组列表
          $scope.getEGroupList();
          $scope.addEGTitle = '';
          $scope.addEGText = '';

          $('.createEvidence').fadeOut();
        }
      })
    } else {
      //修改
      caseBarDetailZhengService.updateEGroupName($scope.updateGroupId, $scope.addEGTitle, $scope.addEGText, $scope.loginId).then(function (data) {
        $rootScope.loadingShow = false;
        $rootScope.fadeShow = false;
        if (data.code == 1) {
          $scope.addEGTitle = '';
          $scope.addEGText = '';
          //刷新证据组列表
          $scope.getEGroupList();
          $('.createEvidence').fadeOut();
        }
      });
    }
  };

    //获取证据列表
  // $scope.getEPollListFF = function () {
  //   var isAll = false;
  //   if($scope.evidenceGroupId == 1){//isAll：未分组（2）、全部（1）--1、
  //     isAll = "1";
  //   }else if($scope.evidenceGroupId == 2){
  //     isAll = "0";
  //   }else {
  //     isAll = 0
  //   }
  //   $rootScope.loadingShow = true;
  //   $rootScope.fadeShow = true;
  //   caseBarDetailZhengService.getEPollList(caseId, $scope.evidenceGroupId,isAll).then(function (data) {
  //     $rootScope.loadingShow = false;
  //     $rootScope.fadeShow = false;
  //     if (data.code == 1) {
  //       $scope.EPollList = data.data;
  //       $(this).css('border-left', '3px solid #00BB9C');
  //       $(".unGroupEvidenceP").css('border-left', '0px solid #00BB9C');
  //       $(this).siblings().css('border-left', '1px solid rgb(215,225,232)');
  //       $('.bodyTow .center').css('display', 'none');
  //       $('.bodyTow .haveEviCenter').css('display', 'block');
  //
  //       //修改证据类型的名字
  //       for (var i = 0; i < data.data.length; i++) {
  //         for (var j = 0; j < $scope.ETypeList.length; j++) {
  //           if ($scope.EPollList[i].evidenceTypeId == $scope.ETypeList[j].evidenceTypeCode) {
  //             $scope.EPollList[i].evidenceTypeId = $scope.ETypeList[j].evidenceTypeName;
  //           }
  //         }
  //       }
  //     }
  //   })
  // };
  // $scope.getEPollListFF();

  //获取证据池的内容
  $scope.getEPoll = function (id, $event, text, description) {

    // var event = $event.target;
    // var e = $(event);
    $scope.evidenceNot = false;
    //给证据组的名字赋值
    $scope.EGName = text;
    $scope.EGDescription = description;

    // $(e).css('border-left', '3px solid #5dc2ae');
    // $(e).parents('.allEvidence').siblings('').children('p').css('border-left', '0px solid #5dc2ae');

    //给证据组id赋值
    $scope.evidenceGroupId = id;

    $scope.getEPollListFF();
  };

  //显示任务详情面板 -- 右侧边栏
  $scope.showDetailBox = function (task,parentsIndex,parentIndex,index,$event) {

    // 记录上次点击的任务详情信息，
    $scope.tashDetailPara.task = task;
    $scope.tashDetailPara.parentIndex = parentIndex;
    $scope.tashDetailPara.parentsIndex = parentsIndex;
    $scope.tashDetailPara.index = index;
    $scope.tashDetailPara.event = null;

    var caseId = task.task.caseId || task.task.caseid;
    $cookies.put('caseAppId',caseId,{
      expires:expireDate
    });

    // 1 > 案件     2> 证据
    if(caseId != undefined){
      if(task.taskType == 1){
        //显示案件进程详情
        $('.rightComeToZJ').css('right','-700px');
        $('.rightComeTo').animate({
          "right": "0px"
        }, 300);

        $(document).click(function () {
          if (!$(".rightComeTo").css("right",'-700px')) {
            // $(".rightComeTo").css("right",'-700px');
            $('.rightComeTo').stop().animate({
              "right": "-700px"
            }, 100);
          }
        });

        $scope.taskType = 1;

        $('#shuxieqisu').removeClass('hide');
        $('.jtextareaAndSaveBox').addClass('hide');

        $('#jqisuzhunbei').removeClass('hide');
        $('#jqisuzhunbei1').addClass('hide');
        $('.L_evidenceAllot').css('display','none');
        $scope.caseDetailShow2(task.task.id);

      }else if(task.taskType == 2){

        //显示证据任务详情
        $('.rightComeTo').css('right','-700px');
        $('.rightComeToZJ').animate({
          "right": "0px"
        }, 300);
        $(document).click(function () {
          if (!$(".rightComeToZJ").css("right",'-700px')) {
            // $(".rightComeToZJ").css("right",'-700px');
            $('.rightComeToZJ').stop().animate({
              "right": "-700px"
            }, 100);
          }
        });

        $scope.taskType = 2;

        $scope.evidenceGroupName = task.evidenceGroupName;
        //让所有出现编辑的都先隐藏掉
        $('.ztextareaAndSaveBox').css('display', 'none');
        $('#zshuxieqisu').css('display', 'block');

        $('#zqisuzhunbei1').addClass('hide');
        $('#zqisuzhunbei').removeClass('hide');
        $('.L_evidenceAllot').css('display','none');
        $scope.getEGroupList($cookies.get('caseAId'));
        $scope.evidenceDetailShow2(task.task.id);

      }
      if($event) {
        $event.stopPropagation();
      }
    }
  };

//     //证据详情
//     //证据详情.点击证据的P出现
    $scope.evidenceDetailShow = function (pClickId) {
    //显示详情界面
    //   $('.rightComeToZJ').css('right','-700px');
    //   $('.rightComeToZJ').animate({
    //         "right": "0"
    //     }, 300);

        //让所有出现编辑的都先隐藏掉
        $('.ztextareaAndSaveBox').css('display', 'none');
        $('#zshuxieqisu').css('display', 'block');

        $('#zqisuzhunbei1').addClass('hide');
        $('#zqisuzhunbei').removeClass('hide');
        //给证据的ID赋值
      $scope.taskType = 2;
      $scope.evidenceID = pClickId;
        // $rootScope.loadingShow = true;
        // $rootScope.fadeShow = true;
        caseBarDetailZhengService.getEDetail(pClickId).then(function (data) {
            // $rootScope.loadingShow = false;
            // $rootScope.fadeShow = false;
            if (data.code == 1) {
                // $scope.caseId = data.data.caseId;

              $scope.evidenceActualHour = data.data.actualHour;//实际工时
              $scope.evidenceEstimateHour = data.data.estimateHour;//预计工时
              $scope.detailData = data.data;
              $scope.detailFJ = data.data.caseTaskAttses;
              $scope.detailList = data.data.task;
              $scope.checkList = data.data.caseTaskCheckList;
              $scope.detailUser = data.data.taskExecutors;
              $scope.evidenceCheckList = data.data.caseTaskCheckList;//检查项


                if($scope.evidenceCheckList == 0){
                  $scope.evidenceCheckItem = false;
                }else {
                  $scope.evidenceCheckItem = true;
                }

              if($scope.detailFJ == 0){
                $scope.attachmentEvidence = false;
              }else {
                $scope.attachmentEvidence = true;
              }

                //刷新检查项的状态
                evidenceRefreshProgressBar();

                //给taskId赋值
                $scope.addLSTaskId = $scope.detailData.task.evidenceTask.id;

                //修改证据类型的名字
                var index = $scope.detailData.evidenceTypeId - 1;
                $('#usertype3').get(0).selectedIndex = index;
                $('#usertype4').get(0).selectedIndex = index;

                //详情->获取在哪个证据组
                $('.zEvidenceGName').val($scope.detailData.evidenceGroupId);

                //获取详情属于哪个证据组
                if($scope.EGroupList){
                    for(var i = 0;i<$scope.EGroupList.length;i++){
                      if($scope.detailData.evidenceGroupId == $scope.EGroupList[i].id){
                          $scope.detailEGName = $scope.EGroupList[i].evidenceGroupName;
                      }
                    }
                }

                //文字带入到输入框中
                $('.zjdetailtextarea').val($scope.detailData.description);
                $('.zjdetailbz').val($scope.detailData.remark);
            }
        });
        //评论
        $scope.gerECommeng();
    };

    $scope.evidenceDetailShow2 = function (pClickId) {
    //显示详情界面
    $('.rightComeToZJ').css('right','-700px');
    $('.rightComeToZJ').animate({
      "right": "0"
    }, 300);

    //让所有出现编辑的都先隐藏掉
    $('.ztextareaAndSaveBox').css('display', 'none');
    $('#zshuxieqisu').css('display', 'block');

    $('#zqisuzhunbei1').addClass('hide');
    $('#zqisuzhunbei').removeClass('hide');
    //给证据的ID赋值
    $scope.taskType = 2;
    $scope.evidenceID = pClickId;
    // $rootScope.loadingShow = true;
    // $rootScope.fadeShow = true;
    caseBarDetailZhengService.getEDetail(pClickId).then(function (data) {
      // $rootScope.loadingShow = false;
      // $rootScope.fadeShow = false;
      if (data.code == 1) {
        // $scope.caseId = data.data.caseId;
        $scope.evidenceActualHour = data.data.actualHour;//实际工时
        $scope.evidenceEstimateHour = data.data.estimateHour;//预计工时
        $scope.detailData = data.data;
        $scope.detailFJ = data.data.caseTaskAttses;
        $scope.detailList = data.data.task;
        $scope.checkList = data.data.caseTaskCheckList;
        $scope.detailUser = data.data.taskExecutors;
        $scope.evidenceCheckList = data.data.caseTaskCheckList;//检查项

        // $scope.detailList = data.data.task;
        // $scope.detailAll = data.data;
        // console.log("$scope.detailAll",$scope.detailAll)
        // $scope.plList = data.data.caseTaskReviews;
        // $scope.executors = data.data.taskExecutors;
        // $scope.logList = data.data.taskLogs;
        // $scope.fileList = data.data.caseTaskAttses;
        // $scope.checkList = data.data.caseTaskCheckList;
        // console.log("$scope.checkList",$scope.checkList)
        // $scope.caseStageName = data.data.task.caseStage.name;

        if($scope.evidenceCheckList == 0){
          $scope.evidenceCheckItem = false;
        }else {
          $scope.evidenceCheckItem = true;
        }

        if($scope.detailFJ == 0){
          $scope.attachmentEvidence = false;
        }else {
          $scope.attachmentEvidence = true;
        }

        //刷新检查项的状态
        evidenceRefreshProgressBar();

        //给taskId赋值
        $scope.addLSTaskId = $scope.detailData.task.evidenceTask.id;

        //修改证据类型的名字
        var index = $scope.detailData.evidenceTypeId - 1;
        $('#usertype3').get(0).selectedIndex = index;
        $('#usertype4').get(0).selectedIndex = index;

        //详情->获取在哪个证据组
        $('.zEvidenceGName').val($scope.detailData.evidenceGroupId);

        //获取详情属于哪个证据组
        if($scope.EGroupList){
          for(var i = 0;i<$scope.EGroupList.length;i++){
            if($scope.detailData.evidenceGroupId == $scope.EGroupList[i].id){
              $scope.detailEGName = $scope.EGroupList[i].evidenceGroupName;
            }
          }
        }

        //文字带入到输入框中
        $('.zjdetailtextarea').val($scope.detailData.description);
        $('.zjdetailbz').val($scope.detailData.remark);
      }
    });
    //评论
    $scope.gerECommeng();
  };

    //详情的描述,出现编辑框
    $scope.showTextareaBox = function ($event,TYPE) {
      getType()
        if($rootScope.typeIf!=7){
            var $event = $event.target;
            var e = $($event);

            $('#zshuxieqisu').css('display', 'none');
            $('.ztextareaAndSaveBox').css('display', 'block');

            $('#zqisuzhunbei').addClass('hide');
            $('#zqisuzhunbei1').removeClass('hide');
        }else{

          $('#zshuxieqisu').css('display', 'block');
          $('.ztextareaAndSaveBox').css('display', 'none');
        }

    };
    //隐藏详情描述
    $scope.hideAddDetailBox = function ($event) {

        var $event = $event.target;
        var e = $($event);

        $(e).parents('.ztextareaAndSaveBox').css('display', 'none');
        $(e).parents('.ztextareaAndSaveBox').siblings('#zshuxieqisu').css('display', 'block');

        $('#zqisuzhunbei1').addClass('hide');
        $('#zqisuzhunbei').removeClass('hide');
    };

    //详情的备注
    $scope.showTextareaBox1 = function ($event) {
      getType()
      var $event = $event.target;
      var e = $($event);
        if($rootScope.typeIf!=7){
            $(e).parents('#zshuxieqisu1').css('display', 'none');
            $(e).parents('#zshuxieqisu1').siblings('.ztextareaAndSaveBox1').css('display', 'block');
        }else{
          $(e).parents('#zshuxieqisu1').css('display', 'block');
          $(e).parents('#zshuxieqisu1').siblings('.ztextareaAndSaveBox1').css('display', 'none');
        }

    };
    //隐藏详情备注
    $scope.hideAddDetailBox1 = function ($event) {
        var $event = $event.target;
        var e = $($event);

        $(e).parents('.ztextareaAndSaveBox1').css('display', 'none');
        $(e).parents('.ztextareaAndSaveBox1').siblings('#zshuxieqisu1').css('display', 'block');
    };

    //修改详情详情
    $scope.updateDetailX = function (evidenceEstimateHour,evidenceActualHour,updateDetailXInput) {//updateDetailXInput
      var egid = $('.zEvidenceGName option:selected').val();
        var name = $('.zEvidenceName').val();
        // var params = {
        //   "taskId":$scope.detailTaskId,
        //   "content": $scope.detailList.content,
        //   "deadLine":$scope.detailList.deadline,
        //   "title":$scope.detailList.title,
        //   "creatorId":$scope.loginId,
        //   "caseId":$cookies.get('caseAppId'),
        //   "userName":$scope.userName,
        //   "estimateHour":$scope.detailList.estimateHour,
        //   'actualHour':$scope.detailList.actualHour
        // };
        var params={
          "evidenceId":$scope.evidenceID,
          "creatorId":$scope.loginId,
          "status":"0",
          "evidenceTypeId":null,
          "description":updateDetailXInput,
          "remark":null,
          "evidenceGroupId":egid,
          "evidenceName":name,
          "estimateHour":$scope.detailList.estimateHour,
          "actualHour":$scope.detailList.actualHour
        };
        caseBarDetailZhengService.updateEDetail(params).then(function (data) {//updateDetailXInput
            // $rootScope.loadingShow = false;
            // $rootScope.fadeShow = false;
            if (data.code == 1) {
                $scope.evidenceDetailShow($scope.evidenceID);
                $('.ztextareaAndSaveBox').css('display', 'none');
                $('#zshuxieqisu').css('display', 'block');
                $('#zqisuzhunbei1').addClass('hide');
                $('#zqisuzhunbei').removeClass('hide');
                $scope.getEPollListFF();
                $scope.getEGroupList();
                refreshTaskListByState(2);
            }
        });
    };

    //修改详情备注
    $scope.updateDetailB = function (inputText) {
      var params={
        "evidenceId":$scope.evidenceID, //证据ID
        "creatorId":$scope.loginId,//
        "status":"0", //状态   0未完，1完成，9删除
        "remark":$scope.detailData.task.remark,//证据备注
      };
      caseBarDetailZhengService.updateEDetail(params).then(function (data) {
          if (data.code == 1) {
              //刷新详情界面
              $scope.evidenceDetailShow($scope.evidenceID);
              $('.ztextareaAndSaveBox1').css('display', 'none');
              $('#zshuxieqisu1').css('display', 'block');
          }
      });

    };

    //修改案件类型
    //获取Select选择的Value
    $("#usertype3").change(function () {
        var courtId = $('#usertype3 option:selected').val();
        var params={
          "evidenceId":$scope.evidenceID, //证据ID
          "creatorId":$scope.loginId,//
          "status":"0", //状态   0未完，1完成，9删除
          "evidenceGroupId":courtId,//证据备注
        };
        caseBarDetailZhengService.updateEDetail(params).then(function (data) {
            if (data.code == 1) {
                //刷新详情界面
                $scope.evidenceDetailShow($scope.evidenceID);
                //刷新证据池
                $scope.getEPollListFF();
            }
        });
    });
    //修改案件类型
    //获取Select选择的Value
    $("#usertype4").change(function () {
        var courtId = $('#usertype4 option:selected').val();
        caseBarDetailZhengService.updateEDetail($scope.evidenceID, $scope.loginId, "1", courtId, null, null).then(function (data) {
            if (data.code == 1) {
                //刷新详情界面
                //$scope.evidenceDetailShow($scope.evidenceID);
                //刷新证据池
                //$scope.getEPollListFF();
            }
        });
    });

    //删除证据
    $scope.deleteEDetail = function () {
      $('#zjdeletedeleteModalpanel').modal('show');
      $('.rightComeToZJ').animate({
            "right": "-700"
        }, 300);
    };
    //删除证据
    $scope.zjdeleteupdateNameConfirm = function () {
        $rootScope.loadingShow = true;
        $rootScope.fadeShow = true;
        var caseId = $cookies.get('caseAppId');
        caseBarDetailZhengService.deleteEDetail(caseId,$scope.evidenceID, $scope.loginId).then(function (data) {
            $rootScope.loadingShow = false;
            $rootScope.fadeShow = false;
            if (data.code == 1) {
              //刷新列表 taskType = 2
              refreshTaskListByState(2);
              $('#zjdeletedeleteModalpanel').modal('hide');
            }
        });
    };


    //最底部的评论和日志
    //获取评论
    $scope.gerECommeng = function () {
        //评论接口
        $rootScope.loadingShow = true;
        $rootScope.fadeShow = true;
        caseBarDetailZhengService.getEComment($scope.evidenceID).then(function (data) {
            $rootScope.loadingShow = false;
            $rootScope.fadeShow = false;
            if (data.code == 1) {
                $scope.plData = data.data;

                //评论的图片
                for(var i=0;i<$scope.plData.length;i++){
                    if($scope.plData[i].biglawuser.icon != null){
                        $scope.plData[i].biglawuser.icon = $scope.plData[i].biglawuser.icon;
                    }
                }
            }
        });
    };
    //日志
    $scope.getELog = function () {
        $rootScope.loadingShow = true;
        $rootScope.fadeShow = true;
        caseBarDetailZhengService.getELog($scope.evidenceID).then(function (data) {
            $rootScope.loadingShow = false;
            $rootScope.fadeShow = false;
            if (data.code == 1) {
              $scope.rzData = data.data;
            }
        });
    };

    //showpl
    $scope.showPlBox = function ($event) {
        var $event = $event.target;
        var e = $($event);

        $(e).parents('.register-navTitle').siblings('.plDiv').css('display', 'block');
        $(e).parents('.register-navTitle').siblings('.rwrzDiv').css('display', 'none');
        $(e).css('border-bottom', '2px solid #00BB9C');
        $(e).siblings('.rwrz').css('border-bottom', '0px solid #00BB9C');

        $('#zhalf2').css('display', 'block');

        $scope.gerECommeng();
    };
    //showrwrz
    $scope.showRwrzBox = function ($event) {
        var $event = $event.target;
        var e = $($event);

        $(e).parents('.register-navTitle').siblings('.plDiv').css('display', 'none');
        $(e).parents('.register-navTitle').siblings('.rwrzDiv').css('display', 'block');
        $(e).css('border-bottom', '2px solid #00BB9C');
        $(e).siblings('.pl').css('border-bottom', '0px solid #00BB9C');

        $('#zhalf2').css('display', 'block');

        $scope.getELog();
    };

    //发布评论
    $scope.sendCommentZ = function () {
        $rootScope.loadingShow = true;
        $rootScope.fadeShow = true;
        caseBarDetailZhengService.insertEComment($scope.evidenceID, $scope.loginId, $scope.commentInput).then(function (data) {
            $rootScope.loadingShow = false;
            $rootScope.fadeShow = false;
            if (data.code == 1) {
                $scope.gerECommeng();
                $scope.commentInput = '';
                //获取证据组列表
                $scope.getEPollListFF();
                refreshTaskListByState(2);
            }
        });
    };

    $scope.init = function () {
    /*如果是归档案件不可编辑*/
    if ($rootScope.typeIf==7) {
      $('#add-zjz-hide').hide();//添加证据组
      $('#select-hide').attr("disabled", "disabled");//选择证据
      $('#search2-hide').hide();//快速搜索
      $('#search1-hide').attr("disabled", "disabled");//快速搜索
      $('#shuxieqisu').hide();//诉讼请求
      $('#shuxieqisu-hide').hide();//诉讼请求
    }else{
      $('#shuxieqisu').show();//诉讼请求
      $('#shuxieqisu-hide').show();//诉讼请求
    }

    /*用于固定导航条*/
    sessionStorage.navNum = 3;

    //点击新增
    $('.footer').click(function () {
      $(this).siblings('.createEvidence').fadeIn();
      $scope.addOrUpdataName = '1';

      $('#addEGName').val('');
      $('#addEGDisp').val('');
    });

    //点击添加框里边的取消
    $('.cannel').click(function () {
      $(this).parents('.createEvidence').fadeOut();
    });


    //点击Li第二个大的Body出现数据
    $('.sigleEvidence li').click(function () {
      // $(this).css('border-left','3px solid #00BB9C');
      // $(this).siblings().css('border-left','1px solid rgb(215,225,232)');
      // $('.bodyTow .center').css('display','none');
      // $('.bodyTow .haveEviCenter').css('display','block');
    });

    //点击具体证据出现详情界面
    //$('.haveEviCenter li').click(function () {
    //    $('.rightComeToZJ').animate({
    //        "right": "0"
    //    }, 300);
    //});
    //点击X号关闭详情页面
    $('.closeDetail').click(function () {
      $(this).parents('.rightComeToZJ').animate({
        "right": "-700"
      }, 300);
      $('.L_evidenceAllot').css('display','none');
    });
  };

    $scope.init();

    //出现添加律师成员的列表,获取请求
    $(".addlvshi").on("click", function () {
        var caseId = $cookies.get('caseAppId');
        $(".L_evidenceAllot").removeClass('hide').show();
        caseBarDetailZhengService.getLawyers(caseId,$scope.evidenceID).then(function (data) {
            if (data.code == 1) {
                $scope.CaseLawyerTianSelect = data.data;
            }
        });

    });

    //分配给
  $scope.PerEvidenceList = [];
  $scope.taskEvidence = taskEvidence;
  $scope.evidencePer = evidencePer;
  function taskEvidence(name, id) {
    //排除相同的律师
    for(var i=0;i<$scope.PerEvidenceList.length; i++) {
       if(id == $scope.PerEvidenceList[i].id) {
          break;
       }
    }
    var item = {
      id:id,
      name:name
    };
    $scope.PerEvidenceList.push(item);
    $(".LawyerAddBody").addClass('hide');
  }

  //删除--分配人员
  function evidencePer(index) {
    $scope.PerEvidenceList.splice(index,1);
  }

    //添加律师成员
    $scope.CaseLawyerTianButton = function (name, id,caseId) {
      caseBarDetailZhengService.addLawyers($scope.addLSTaskId, id, name, $scope.loginId, $scope.evidenceID,$scope.userPortraitName,$scope.detailData.evidenceName,caseId).then(function (data) {
            if (data.code == 1) {
              //刷新详情界面
              $scope.evidenceDetailShow($scope.evidenceID);
              // $(".rightComeToZJ").css("display","none");
              $(".L_evidenceAllot").css("display","none");
              var item = data.data;
              $scope.PerEvidenceList.push(item);
              // $scope.evidenceAllot = false;
              refreshTaskListByState(2);
            }else if(data.code == 0){
              $(".L_evidenceAllot").css("display","none");
            }
        })
    };
    //删除律师
    $scope.deleteLawyer = function (name, id,index) {
        // $rootScope.loadingShow = true;
        // $rootScope.fadeShow = true;
      if($rootScope.type!=7){
        bootbox.dialog({
          message: "确定删除?",
          title: "提示信息",
          className:'d-promptBox',
          buttons: {
            OK: {
              label: "确定",
              className: "d-btn-confirm",
              callback: function () {
                caseBarDetailZhengService.deleteLawyers($scope.addLSTaskId, id, name, $scope.loginId, $scope.evidenceID).then(function (data) {
                  // $rootScope.loadingShow = false;
                  // $rootScope.fadeShow = false;
                  if (data.code == 1) {
                    $scope.detailUser.splice(index,1);
                    //刷新详情界面
                    // $scope.evidenceDetailShow($scope.evidenceID);
                    refreshTaskListByState(2);
                  }
                });
              }
            },
            Cancel: {
              label: "取消",
              className: "d-btn-cancel",
              callback: function () {

              }
            }
          }
        });
      }

    };

    //给证据组重新命名
    $scope.updateName = function ($event,name,disp) {
    var $event = $event.target;
    var e = $($event);

    $('.createEvidence').fadeIn();
    $(e).parents('.updateBox').css('display','none');

    $scope.addOrUpdataName = '2';

    $scope.addEGTitle = name;
    $scope.addEGText = disp;

  };

    //点击取消
    $scope.deleteCancelConfirm = function () {
        $('#deleteEGroupButHaveE').modal('hide');
        $('#deleteEGroup').modal('hide');
    };

    // 日期选择器
  if($rootScope.typeIf!=7){
    $(".form_datetime_panel").datetimepicker({
      minView: "month",
      format: 'yyyy-mm-dd',
      language: "zh-CN",
      charset: "utf-8"
    });

    //更改日期事件
    $('.form_datetime_panel')
      .datetimepicker()
      .on('changeDate', function (ev) {
        $('.form_datetime_panel').datetimepicker('hide');
        var d = new Date(ev.date);
        var month = d.getMonth() + 1 > 9 ? d.getMonth() + 1 : '0' + (d.getMonth() + 1);
        var day = d.getDate() > 9 ? d.getDate() : '0' + d.getDate();
        var date = d.getFullYear() + '-' + month + '-' + day;
        $scope.detailList.deadline = date;
        if($scope.taskType == 1) {
          //案件进程
          var params = {
            "taskId":$scope.detailTaskId,
            "content": "",
            "deadLine":$scope.detailList.deadline,
            "title":$scope.detailList.title,
            "creatorId":$scope.loginId,
            "caseId":$cookies.get('caseAppId'),
            "userName":$scope.userName,
            "estimateHour":$scope.detailList.estimateHour,
            'actualHour':$scope.detailList.actualHour
          };
          caseBarDetailjinchengService.updateDateOrDes(params).then(function (data) {
            if(data.code == 1){
              //刷新详情
              $scope.caseDetailShow($scope.detailTaskId);
              refreshTaskListByState(1)
            }
          });
        } else if($scope.taskType == 2){
          //证据任务
          caseBarDetailZhengService.updateEDDate($scope.evidenceID,$scope.loginId,date).then(function (data) {
            if (data.code == 1) {
              //刷新证据的详情的信息
              $scope.evidenceDetailShow($scope.evidenceID);
              refreshProgressBar(2)
            }
          });
        }
      });
  }








    //附件上传--证据
    $('.TJFJ').change(function () {
        //这个就是
        //上传附件
        var Fdata = new FormData();

        Fdata.append('filename1',this.files[0]);
        Fdata.append('evidenceId',$scope.evidenceID);
        Fdata.append('creatorId',$scope.loginId);
        Fdata.append('caseId',$cookies.get('caseAppId'));

        $rootScope.loadingShow = true;
        $rootScope.fadeShow = true;
        caseBarDetailZhengService.uploadFile(Fdata).then(function (data) {
          if(data.code==1){
            $rootScope.loadingShow = false;
            $rootScope.fadeShow = false;
            //刷新证据的详情的信息
            $scope.evidenceDetailShow($scope.evidenceID);
            var item = {
              'creatorId':data.data.creatorId,
              'evidenceId':data.data.evidenceId,
              'filePact':data.data.filePact,
              'fileSize':data.data.fileSize,
              'id':data.data.id,
              'name':data.data.name,
            };
            $scope.detailFJ.push(item);
            refreshTaskListByState(2);
          }
        })

    });

  $scope.showFileSuffixEvidence = function (fileName) {
    var suffix = "";
    if(fileName){
      var str= fileName.split(".");
      suffix = str[str.length-1];
      suffix = suffix.toLowerCase();
      var fileTypeList = [ 'xlsx' , 'doc' , 'html' , 'jpg', 'pdf' , 'png' , 'ppt' , 'txt' , 'xls' , 'docx'];
      if(fileTypeList.indexOf(suffix) == -1){
        suffix = "empty";
      }
    }
    return suffix;
  };

    //删除附件
    $scope.deleteFile = function (id,name) {
      if($rootScope.typeIf!=7){
        caseBarDetailZhengService.deleteFile(id,$scope.evidenceID,name,$scope.loginId).then(function (data) {
          if(data.code == 1){
            //刷新证据的详情的信息
            $scope.evidenceDetailShow($scope.evidenceID);
          }
        });
      }
    };

    $scope.closeEvidence = closeEvidence;
    $scope.openEvidence = openEvidence;

    $scope.showParams = {
      evidenceAll:false,
    };
    //打开导出证据弹窗
  function openEvidence() {
    $scope.showParams.evidenceAll = true;
    $scope.showEAllList();
  }
    //关闭弹窗
  function closeEvidence() {
    $scope.showParams.evidenceAll = false;
  }

  //检查项--添加  接口
  $scope.checkedEvidenceAdd = function () {
    var params = {'checkName':$scope.evidenceCheck.checkname,'evidenceId':$scope.evidenceID};
    caseBarDetailZhengService.checkedEvidenceAdd(params).then(function (response){
      if(response.data.code == 1){
        $scope.showCheckItem.CheckItem = false;
        $scope.showCheckItem.addCheckItem = true;
        $scope.addCheckedStatus = response.data.status;
        var item = {
          "checkname":response.data.data.checkname,
          "id":response.data.data.id,
        };
        $scope.evidenceCheckList.push(item);
        evidenceRefreshProgressBar();
        refreshTaskListByState(2);
      }
      $scope.showCheckItem.CheckItem = false;
      $scope.showCheckItem.addCheckItem = true;
      $scope.evidenceCheck.checkname = '';
    })
  };

  //证据清单--检查项进度条
  function evidenceRefreshProgressBar() {
    var evidenceChecked = 0;
    if(!$scope.evidenceCheckList) {
      return ;
    }
    for(var i=0;i<$scope.evidenceCheckList.length;i++) {
      if ($scope.evidenceCheckList[i].status == 5) {
        evidenceChecked++;
      }
    }
    $scope.evidenceCheckList.EvidCheckList = evidenceChecked;
    if(evidenceChecked.status != 5){
      $('.L_progressBaring').css({
        "width":(evidenceChecked/$scope.evidenceCheckList.length)*430+'px',
        "height":'10px',
        'background':'#00bfb5',/*#e6e6e6*/
        'border-radius':'10px',
        '-webkit-transition': 'width 2s',  /* Safari and Chrome */
        '-moz-transition':'width 2s',  /* Firefox  */
        '-o-transition':'width 2s'  /* Opera */
      })
    }
    // else if(checked.status == 5){
    //   $('.L_progressBaring').css({
    //     "width":(evidenceChecked/$scope.evidenceCheckList.length)*402+'px',
    //     "height":'10px',
    //     'background':'#e6e6e6',
    //     'border-radius':'10px',
    //     '-webkit-transition': 'width 2s',  /* Safari and Chrome */
    //     '-moz-transition':'width 2s',  /* Firefox  */
    //     '-o-transition':'width 2s'  /* Opera */
    //   })
    // }
  };

  //检查项--删除 接口
  $scope.checkedEvidenceDel = function (index,evidenceObj) {
    var params = {"checkId":evidenceObj.id};
    caseBarDetailZhengService.checkedEvidenceDel(params).then(function (response) {
      if(response.data.code == 1){
        //刷新进度条
        evidenceRefreshProgressBar();
        //刷新证据检查项列表
        // $scope.evidenceDetailShow();

        $scope.evidenceCheckList.splice(index,1);
        evidenceObj.showEditCheck = false;
        if($scope.evidenceCheckList.length == 0){
            $scope.evidenceCheckItem = false;
        }
        refreshTaskListByState(2);
      }
    });
  };
  //检查项--编辑  接口
  $scope.checkedEvidenceEdit = function (evidenceObj) {
    var params = {"checkId":evidenceObj.id,"checkStatus":evidenceObj.status,"checkname":evidenceObj.checkname};
    caseBarDetailZhengService.checkedEvidenceEdit(params).then(function (response) {
      evidenceObj.showEditCheck= false;
    })
  };

  //检查项的--check状态
  $scope.changeEvidenceObjCheckListStatus = function (evidenceObj) {
    switch (evidenceObj.status){
      case 1: evidenceObj.status = 5;
        break;
      case 5: evidenceObj.status = 1;
        break;
      case undefined: evidenceObj.status = 5;
        break;
    }
    evidenceRefreshProgressBar();
    $scope.checkedEvidenceEdit(evidenceObj);
  };
  // 附件下载---证据
  $scope.downloadAttachment = function (fj) {
    var params = {'caseid':$cookies.get('caseAppId'),'evidenceId':$scope.evidenceID,'evidenceAttachedId':fj.id};
    caseBarDetailZhengService.downloadAttachment(params).then(function (response) {
      var file = new Blob([response.data]);
      var link = document.createElement('a');
      link.href = URL.createObjectURL(file);
      link.download = fj.name;
      link.click();
      window.URL.revokeObjectURL(link.href);
    });
  };

  //评论随滚动条滚动
  var commentBox = $("#input-comment").offset().top;
  $(window).scroll(function () {
   // var offsetTop = commentBox + $(window).scrollTop() + "px";
    //$("#input-comment").animate({ top: offsetTop }, { duration: 600, queue: false });
  });

  /**
   * 通过任务类型及当前所在页面调用不同刷新列表方法
   * workBarNoWork 工作台，
   * @param taskType 1.案件进程 2.证据任务
   */
  function refreshTaskListByState(taskType) {

    var info = {
      detailAll: $scope.detailAll,
      parentIndex:$scope.tashDetailPara.parentIndex,
      index:$scope.tashDetailPara.index,
      parentsIndex:$scope.tashDetailPara.parentsIndex
    }
    if ($state.current.name == 'workBarNoWork') {
      //工作台 刷新工作台
      $scope.$broadcast('refreshWorkbarNoWork', info);
    } else {
      //案件进程
      if(taskType == 1) {
        //刷新进程列表
        // $scope.getList();
        $scope.$broadcast('refreshCaseTask', info);
      }

      if (taskType == 2) {
        $scope.$broadcast('refreshEvidenceTask', null);
        //刷新证据组
        // $scope.getEGroupList();
        //刷新证据池子
        // $scope.getEPollListFF();
      }
    }
  }

  //获取证据列表
  $scope.getEPollListFF = function () {
    var isAll = false;
    if($scope.evidenceGroupId == 1){//isAll：未分组（2）、全部（1）--1、
      isAll = "1";
    }else if($scope.evidenceGroupId == 2){
      isAll = "0";
    }else {
      isAll = 0
    }
    caseBarDetailZhengService.getEPollList($cookies.get('caseAppId'), $scope.evidenceGroupId,isAll).then(function (data) {
      if (data.code == 1) {
        $scope.EPollList = data.data;
        //附件
        $scope.evidenceAttached = data.evidenceAttached;

        //$(this).css('border-left', '3px solid #00BB9C');
        $(".unGroupEvidenceP").css('border-left', '0px solid #00BB9C');
        //$(this).siblings().css('border-left', '1px solid rgb(215,225,232)');
        $('.bodyTow .center').css('display', 'none');
        $('.bodyTow .haveEviCenter').css('display', 'block');

        //修改证据类型的名字
        for (var i = 0; i < data.data.length; i++) {
          for (var j = 0; j < $scope.ETypeList.length; j++) {
            if ($scope.EPollList[i].evidenceTypeId == $scope.ETypeList[j].evidenceTypeCode) {
              $scope.EPollList[i].evidenceTypeId = $scope.ETypeList[j].evidenceTypeName;
            }
          }
        }
      }
    })
  };


  //意见反馈
  $scope.init = function(){

    $scope.feedbackContent = '';
    // $("#feedbackModal").modal('show');

    $(".feedback-close").click(function () {

      $("#feedbackModal").modal('hide');
      // $state.go("caseBar");
    });
    // $(".modal-backdrop").remove();//删除class值为modal-backdrop的标签，可去除阴影
  };
  $scope.init();/*初始化函数*/

  $scope.feedbackShow = function () {
    $(".feedback-success").hide();
    $(".feedback-main").show();
  };

  // 关闭弹出框时，清空输入框，并隐藏反馈成功界面
  $('#feedbackModal').on('hidden.bs.modal', function () {
    $scope.feedbackContent = "";
    $(".feedback-success").hide();
    $(".feedback-main").show();
    // $state.go("caseBar");
  });

  $scope.feedbackCommit = function () {
    if($scope.feedbackContent != ''){
      $(".content-empty").fadeOut();
      $rootScope.loadingShow = true;
      $rootScope.fadeShow = true;
      feedbackService.feedback($scope.feedbackContent).then(function (response) {
        $rootScope.loadingShow = false;
        $rootScope.fadeShow = false;
        if (response.code == 1) {
          $(".feedback-main").hide();
          $(".feedback-success").show();
          $scope.feedbackContent = "";
          // $(".modal-backdrop").remove();//删除class值为modal-backdrop的标签，可去除阴影
          // $('#feedbackModal').css('display','none');
          // $('.modal-backdrop.in').css('opacity','0');
        }
      }, function (response) {
        console.error('feedbackCommit error', response.status, response.statusText);
      });
    }else {
      $(".content-empty").fadeIn();
      setTimeout(function () {
        $(".content-empty").fadeOut();
      }, 3000);
    }
  };
  //邀请好友
  $scope.searchText = '';

  /*登录ID*/
  var loginId = kbt.decrypt($cookies.get('cookieUserId'));
  //用户名
  var loginName = kbt.decrypt($cookies.get('cookieUserName'));

  $scope.init = function(){

    // $("#invitationModal").modal('show');

    $(".yb-img-close").click(function () {
      $("#invitationModal").modal('hide');
    });

    $('.yb-input').bind('keypress',function(event){
      if(event.keyCode == '13')
      {
        $scope.search();
      }
    });
  };
  $scope.init();/*初始化函数*/

  // 关闭弹出时，清空界面输入值
  $('#invitationModal').on('hidden.bs.modal', function () {
    $scope.searchText = '';
    $(".yb-result").hide();
    $(".sendSuccess").hide();
    $('#invitationInput').removeClass('writeError');
    $('.error_input').fadeOut();
  });


  $scope.search = function () {

    $('#invitationInput').removeClass('writeError');
    $('.error_input').fadeOut();

    if($scope.searchText != ''){
      if($scope.searchText.indexOf("@")>=0){  //邮箱搜索
        if(CheckMail($scope.searchText)){
          $rootScope.loadingShow = true;
          $rootScope.fadeShow = true;

          invitationService.search("",$scope.searchText).then(function (response) {
            $rootScope.loadingShow = false;
            $rootScope.fadeShow = false;

            $(".yb-result").show();
            if (response.code == 1) {
              $scope.refresh(response);
            }
          }, function (response) {
            $rootScope.loadingShow = false;
            $rootScope.fadeShow = false;
            console.error('search error', response.status, response.statusText);
          });
        }else {
          $('#invitationInput').addClass('writeError');
          $('.error_input').fadeIn();
          $('.error_input').children('p').html('输入的邮箱格式不正确');
        }
      }else {
        if (checkPhone($scope.searchText)) { // 手机号搜索
          $rootScope.loadingShow = true;
          $rootScope.fadeShow = true;

          invitationService.search($scope.searchText, "").then(function (response) {
            $rootScope.loadingShow = false;
            $rootScope.fadeShow = false;

            $(".yb-result").show();

            if (response.code == 1) {
              $scope.refresh(response);
            }
          }, function (response) {
            $rootScope.loadingShow = false;
            $rootScope.fadeShow = false;
            console.error('search error', response.status, response.statusText);
          });
        }else {
          $('#invitationInput').addClass('writeError');
          $('.error_input').fadeIn();
          $('.error_input').children('p').html('输入的手机号、邮箱格式不正确');
        }
      }
    }else {
      $('#invitationInput').addClass('writeError');
      $('.error_input').fadeIn();
      $('.error_input').children('p').html('邮箱、手机号不能为空');
    }
  };

  $scope.refresh = function (response) {

    if (response.data.status == 3) { // 已注册
      $scope.user = response.data.biglawuser;
      $(".yz-register").show();
      $(".invitation-btn").hide();
      $(".yz-invitation").hide();

    }else if (response.data.status == 2){ // 已邀请
      $scope.user = {username:$scope.searchText,icon:"img/pepleactiveicon.png"};
      $(".yz-register").hide();
      $(".invitation-btn").hide();
      $(".yz-invitation").show();
    }else {// 未邀请
      $scope.user = {username:$scope.searchText,icon:"img/pepleactiveicon.png"};
      $(".yz-register").hide();
      $(".invitation-btn").show();
      $(".yz-invitation").hide();
    }
  };

  $scope.invitationFriend = function (invitationText) {
    if(invitationText != '') {
      if (invitationText.indexOf("@") >= 0) {
        $scope.invition("",invitationText);
      }else {
        $scope.invition(invitationText,"");
      }
    }
  };

  $scope.invition = function (phone,email) {

    $rootScope.loadingShow = true;
    $rootScope.fadeShow = true;
    invitationService.invitationFriend(phone,email,loginId,loginName).then(function (response) {

      $rootScope.loadingShow = false;
      $rootScope.fadeShow = false;

      if (response.code == 1) {

        $(".yb-result").hide();

        $(".sendSuccess").show();
      }
      $scope.searchText = "";

    }, function (response) {

      $rootScope.loadingShow = false;
      $rootScope.fadeShow = false;
      console.error('invitation error', response.status, response.statusText);
    });
  };



  $('.rightComeTo').click(function (event) {
    event.stopPropagation();
  });
  $('.rightComeToZJ').click(function (event) {
    event.stopPropagation();
  })

$(document).click(function(){
  $('.d-closeSiblings').stop().animate({right:'-700px'});
  $timeout(function(){
    $('.d-closeSiblings').css({display:'none'})
  },301)
});

};
